<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language=javascript src="dialog.js"></script>

<script language=javascript>
document.write ("<link href='../language/" + AvailableLangs["Active"] + ".css' type='text/css' rel='stylesheet'>");
document.write ("<link href='dialog.css' type='text/css' rel='stylesheet'>");

var sAction = "INSERT";
var sTitle = lang["DlgComInsert"];
var sel = dialogArguments.eWebEditor.document.selection.createRange();
sel.type = dialogArguments.eWebEditor.document.selection.type;

var el;
var sMathML = "";
var sBgColor = "#CCCCCC";
var sForeColor = "#000000";

var bInstalled = true;

if (sel.type=="Control") {
	if (sel.item(0).tagName=="APPLET"){
		if (sel.item(0).getAttribute("code",2).toLowerCase()=="webeq3.viewercontrol"){
			sAction = "MODI";
			sTitle = lang["DlgComModify"];
			el = sel.item(0);
			sMathML = getParamValue(el.innerHTML, "eq");
			sMathML = sMathML.replace(/&amp;/, "&" );
			sBgColor = getParamValue(el.innerHTML, "background");
			sForeColor = getParamValue(el.innerHTML, "foreground");
		}
	}
}

document.write("<title>" + lang["DlgEQ"] + "(" + sTitle + ")</title>");

function getParamValue(html, strName){
	var re = new RegExp("<param name=\""+strName+"\" value=\"(.*?)\">","gi") ;
	var myArray = re.exec(html);
	if (myArray){
		return myArray[1];
	}
	return "";
}

function InitDocument() {
	AvailableLangs.TranslatePage(document);

	try{
		d_eq.setMathML(sMathML);
	}catch(e){
		bInstalled = false;
		
	}
	
	if(bInstalled){
		v_normal.style.display = "";
		d_bgcolor.value = sBgColor;
		s_bgcolor.style.backgroundColor = sBgColor;
		d_forecolor.value = sForeColor;
		s_forecolor.style.backgroundColor = sForeColor;
	}else{
		v_install.style.display = "";
		v_installing.innerHTML = "<OBJECT CLASSID='clsid:41649A90-B484-11d1-8D75-00C04FC24EE6' CODEBASE='WebEQInstall.cab#Version=3,0,1,6' HEIGHT=1 WIDTH=1></OBJECT>";
	}
	adjustDialog();
}

function ok(){
	// is valid bgcolor
	sBgColor = d_bgcolor.value;
	sForeColor = d_forecolor.value;
	sMathML = d_eq.getPackedMathML();
	if (!IsColor(sBgColor)){
		BaseAlert(d_bgcolor,lang["ErrColorBg"]);
		return;
	}
	if (sBgColor==""){
		sBgColor = "#FFFFFF";
	}
	if (sForeColor==""){
		sForeColor = "#000000";
	}
	dialogArguments.insertHTML("<APPLET codeBase=./ height=100 width=320 code=webeq3.ViewerControl><PARAM NAME=\"foreground\" VALUE=\"" + sForeColor + "\"><PARAM NAME=\"background\" VALUE=\"" + sBgColor + "\"><PARAM NAME=\"size\" VALUE=\"18\"><PARAM NAME=\"eq\" VALUE=\"" + sMathML + "\"></APPLET>");
	window.returnValue = null;
	window.close();
}


</script>
</HEAD>

<body onload="InitDocument()">
	<table border=0 cellpadding=0 cellspacing=5 id=tabDialogSize>
		<tr>
			<td>


				<table id=v_install border=0 cellpadding=5 cellspacing=10
					style="display: none" align=center>
					<tr>
						<td bgcolor=#ffffff noWrap><span lang=DlgEQInstallAlt></span></td>
					</tr>
				</table>
				<div id=v_installing style="display: none"></div>

				<table border=0 cellpadding=0 cellspacing=0 align=center id=v_normal
					style="display: none">
					<tr>
						<td colspan=2><OBJECT CODE='webeq3.editor.InputControl'
								WIDTH=620 HEIGHT=200 id=d_eq MAYSCRIPT>
								<PARAM NAME=eq VALUE=''>
							</OBJECT></td>
					</tr>
					<tr>
						<td height=8 colspan=2></td>
					</tr>
					<tr>
						<td noWrap><span lang=DlgEQBackground></span>:<input
							type=text id=d_bgcolor size=7 value=""><img border=0
							src="../sysimage/rect.gif" width=18 style="cursor: hand"
							id=s_bgcolor onclick="SelectColor('bgcolor')" align=absmiddle>&nbsp;
							<span lang=DlgEQForeground></span>:<input type=text
							id=d_forecolor size=7 value=""><img border=0
							src="../sysimage/rect.gif" width=18 style="cursor: hand"
							id=s_forecolor onclick="SelectColor('forecolor')" align=absmiddle></td>
						<td noWrap align=right><input type=submit value='' id=Ok
							onclick="ok()" lang=DlgBtnOK>&nbsp;&nbsp;<input
							type=button value='' onclick="window.close();" lang=DlgBtnCancel></td>
					</tr>
				</table>


			</td>
		</tr>
	</table>
</body>
</html>
